<?php
if (!defined("_ECRIRE_INC_VERSION")) return;
global $tables_principales;

function alohacart_declarer_tables_interfaces($interface){
    $interface['table_des_tables']['alohacart_clients'] = 'alohacart_clients';
    $interface['table_des_tables']['alohacart_orders'] = 'alohacart_orders';
    $interface['table_des_tables']['alohacart_orders_products'] = 'alohacart_orders_products';
    $interface['table_des_tables']['alohacart_sources'] = 'alohacart_sources';    
    $interface['table_des_tables']['alohacart_extensions'] = 'alohacart_extensions';
    $interface['table_des_tables']['alohacart_orders_statuts'] = 'alohacart_orders_statuts';
	return $interface;
}

function alohacart_declarer_tables_principales($tables_principales){
    // Orders table
    $alohacart_orders = array(
		"id_order" 	=> "bigint(21) NOT NULL AUTO_INCREMENT",
        "id_statut" 	=> "bigint(21) NOT NULL",
		"date" 		=> "datetime NOT NULL COMMENT 'Order`s add date'",		
        "name" 	=> "varchar(255) NOT NULL COMMENT 'Customer`s name'",
        "phone" 	=> "varchar(255) NOT NULL COMMENT 'Customer`s phone'",
        "email" 	=> "varchar(255) NOT NULL COMMENT 'Customer`s email'",
        "city" 	=> "varchar(255) NOT NULL COMMENT 'Customer`s city'",
        "address" 	=> "varchar(255) NOT NULL COMMENT 'Customer`s address'",
        "order_comments" 	=> "text NOT NULL COMMENT 'Customer`s comments'",
        "id_shipping" 	=> "bigint(21) NOT NULL COMMENT 'Shipping (extension) ID'",
        "shipping_titre" 	=> "varchar(255) NOT NULL COMMENT 'Shipping name'",
        "shipping_cost" 	=> "float NOT NULL COMMENT 'Shipping cost'",
        "shipping_data" 	=> "text NOT NULL COMMENT 'Shipping data'",
        "total_price" 	=> "float NOT NULL COMMENT 'Total price in order`s currency'",
        "id_currency" 	=> "bigint(21) NOT NULL COMMENT 'ID of order`s currency (must be used for display only - all prices are in main currency!)'",
        "currency_rate" => "float NOT NULL COMMENT 'Currency rate on order creation day'",
        "id_payment" 	=> "bigint(21) NOT NULL",
        "payment_titre" 	=> "varchar(255) NOT NULL COMMENT 'Payment name'",
        "payment_data" 	=> "text NOT NULL COMMENT 'Payment data'",
        "source" 	=> "text NOT NULL",
        "medium" 	=> "text NOT NULL",
        "term" 	    => "text NOT NULL",
        "content" 	=> "text NOT NULL",
        "campaign" 	=> "text NOT NULL",
        "segment" 	=> "text NOT NULL",
        "viewed" 	=> "tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Indicates whether orders was viewed'",
        "maj" 	=> "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
		);
	$alohacart_orders_key = array(
		"PRIMARY KEY"	=> "id_order"
		);
	$tables_principales['spip_alohacart_orders'] =
		array('field' => &$alohacart_orders, 'key' => &$alohacart_orders_key);
        
    // Orders statuses table
    $alohacart_orders_statuts = array(
		"id_statut" => "bigint(21) NOT NULL AUTO_INCREMENT",
		"titre" => "text NOT NULL",
        "maj" 	=> "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
		);
	$alohacart_orders_statuts_key = array(
		"PRIMARY KEY"	=> "id_statut"
		);
	$tables_principales['spip_alohacart_orders_statuts'] =
		array('field' => &$alohacart_orders_statuts, 'key' => &$alohacart_orders_statuts_key);    
        
    // Orders products table
    $alohacart_orders_products = array(
        "id_order_product" 	=> "bigint(21) NOT NULL AUTO_INCREMENT",
		"id_order" 	=> "bigint(21) NOT NULL",
		"id_article" => "bigint(21) NOT NULL",
		"sku" 	=> "varchar(255) NOT NULL",
		"titre" 	=> "varchar(255) NOT NULL",
        "quantity" 	=> "int(11) NOT NULL",
        "price" 	=> "float NOT NULL",
        "total_price" 	=> "float NOT NULL",
        "written_off" 	=> "tinyint(1) NOT NULL DEFAULT 0",
        "maj" 	=> "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"                
		);
	$alohacart_orders_products_key = array(
        "PRIMARY KEY"=>"id_order_product",
		"INDEX"=>"id_order, id_article" // TODO: Почему задваиваются индексы после реинстала плагина?        
		);
	$tables_principales['spip_alohacart_orders_products'] =
		array('field' => &$alohacart_orders_products, 'key' => &$alohacart_orders_products_key);    
        
    // Clients table
    $table = array(
		"id_auteur" 	=> "bigint(21) NOT NULL AUTO_INCREMENT",
        "phone" 	=> "varchar(255) NOT NULL COMMENT 'Client phone'",
        "city" 	=> "varchar(255) NOT NULL COMMENT 'Client city'",
        "address" 	=> "varchar(255) NOT NULL COMMENT 'Client address'",
		"maj" 		=> "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
		);
	$table_key = array(
		"PRIMARY KEY"	=> "id_auteur"
		);
	$tables_principales['spip_alohacart_clients'] =
		array('field' => &$table, 'key' => &$table_key);
        
       
    // Sources table        
    $alohacart_sources = array(
		"id_auteur" 	=> "bigint(21) NOT NULL AUTO_INCREMENT",
        "source" 	=> "varchar(255) NOT NULL COMMENT 'источник'",
        "medium" 	=> "varchar(255) NOT NULL COMMENT 'тип трафика'",
        "term" 	=> "varchar(255) NOT NULL COMMENT 'слово'",
        "content" 	=> "varchar(255) NOT NULL COMMENT 'объявление'",
        "campaign" 	=> "varchar(255) NOT NULL COMMENT 'кампания'",
        "segment" 	=> "varchar(255) NOT NULL",
		"maj" 		=> "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
		);
	$alohacart_sources_key = array(
		"PRIMARY KEY"	=> "id_auteur"
		);
	$tables_principales['spip_alohacart_sources'] =
		array('field' => &$alohacart_sources, 'key' => &$alohacart_sources_key);
        
    // Extensions table        
    $alohacart_extensions = array(
		"id_extension" 	=> "bigint(21) NOT NULL AUTO_INCREMENT",
        "titre"      	=> "varchar(255) NOT NULL",
        "type"      	=> "varchar(255) NOT NULL COMMENT 'Extension type'",
        "code" 	        => "varchar(255) NOT NULL COMMENT 'Extension key'",        
        "active" 	    => "tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Extension activity'",
		//"free_from" 	=> "float NOT NULL COMMENT 'Free from price'",
		"maj" 		    => "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
		);
	$alohacart_extensions_key = array(
		"PRIMARY KEY"	=> "id_extension"
		);
	$tables_principales['spip_alohacart_extensions'] =
		array('field' => &$alohacart_extensions, 'key' => &$alohacart_extensions_key);    
    
    return $tables_principales;
}

?>